 <!doctype html>
<html dir="ltr" lang="zh-CN">
    <head>
        <meta charset="utf-8"/>
        <meta http-equiv="X-UA-Compatible" content="IE=Edge">
        <style type="text/css">
     #editor{
        float:left; width:380px;background:#D5F3F4;padding-left:10px;
      }
      #editor span.button{
        display:block;float:left;border: 1px solid  #CCC;margin:1px 5px 1px 0px ;color: #000;
        background: #D0E8FC;width:40px;height:20px;text-align:center;
      }
      #editor select{ display:block; float:left;height:24px;width:60px;margin-right:5px;}
      #textarea {width:382px;height:100px;}
        </style>
        <link rel="stylesheet" href="script/jqm/css/jquery.mobile-1.4.2.min.css"/>
<script src="script/jqm/js/jquery-1.8.2.min.js" type="text/javascript"></script>
<script src="script/jqm/js/jquery.mobile-1.4.2.min.js" type="text/javascript"></script>
<script src="script/cordova.js" type="text/javascript"></script>
<!-- <script src="script/iscroll/iscroll.js" type="text/javascript"></script> -->
<script src="script/report.js" type="text/javascript"></script>
<script src="script/init.js" type="text/javascript"></script>
<script src="script/common.js" type="text/javascript"></script>
<script src="script/model.js" type="text/javascript"></script>
<script src="script/panel.js" type="text/javascript"></script>
<script src="script/bill.js" type="text/javascript"></script>
<script src="script/desEncrypt.js" type="text/javascript"></script>
        <script type="text/javascript">
            var addEvent = (function () {
                if (document.addEventListener) {
                    return function (el, type, fn) {
                        el.addEventListener(type, fn, false);
                    };
                } else {
                    return function (el, type, fn) {
                        el.attachEvent('on' + type, function () {
                            return fn.call(el, window.event);
                        });
                    }
                }
            })();
            var imgsrc="";
            window.onload = function(){
                var editor = document.getElementById("editor");
                var buttons = editor.getElementsByTagName("span");
                //***********************************************************
                var textarea = document.getElementById("textarea");
                textarea.style.display = "none";
                var iframe = document.createElement("iframe");
                iframe.style.width = "390px";
                iframe.style.height = "100px";
                iframe.frameBorder=0;
                textarea.parentNode.insertBefore(iframe,textarea);
                var iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
                iframeDocument.designMode = "on";
                iframeDocument.open();
                iframeDocument.write('<html><head><style type="text/css">body{ font-family:arial; font-size:13px;background:#DDF3FF }</style></head></html>');
                iframeDocument.close();
                //***********************************************************
                for(var i = 0,l= buttons.length;i<l;i++){
                    buttons[i].onclick = new function(){
                        var command=buttons[i].getAttribute("title");
                        return function(){
                            if(command == 'createlink' || command == 'insertimage'){
                            	//var value="image/logo-nav.png";
                            	loadImage();
                            	//alert(imgsrc);
                                var value="image/logo-nav.png";
                                iframeDocument.execCommand(command,false,value);
                            }else{
                                iframeDocument.execCommand(command,false,'');
                            }
                        }
                    };
                };
/*                 for(i=0,l=selects.length;i<l;i++){
                    selects[i].onchange = new function(){
                        var select = selects[i];
                        return function(){
                            var command = select.getAttribute("title"),
                            value = select.options[select.selectedIndex].value;
                            if(command == 'backcolor' && /a/[-1]=='a'){
                                iframeDocument.execCommand('hilitecolor',false,value);
                            }else{
                                iframeDocument.execCommand(command,false,value);
                            }
                        };
                    };
                }; */
            }
            
            /****/
            /*拍照上传*/
 function loadImage() {
     //拍照并显示在屏幕
    navigator.camera.getPicture(onLoadImageSuccess, onLoadImageFail, {destinationType: Camera.DestinationType.FIFE_URL});
 }
 //拍照成功后回调
 function onLoadImageSuccess(imageURI) {alert(111)
	 uploadpic(imageURI);
 alert(222)
	 //uploadImage(imageURI);
    /* var src = "data:image/jpeg;base64," + imageURI;
     $("#getImage").attr("src", src);
     $("#getImage").show(); */
 }
 
 function uploadpic(picUrl) {
	 alert(picUrl);
     var options = new FileUploadOptions();
     options.fileKey="file";
     options.fileName=picUrl.substr(picUrl.lastIndexOf('/')+1);
     alert(options.fileName);
     options.mimeType="image/jpeg";

     var params = new Object();
     params.value1 = "参数1的值哦";
     params.value2 = "参数2的值";
     options.params = params;

     var ft = new FileTransfer();
		var url="http://192.168.1.127:908/mobilephone/upload.asp?userid=8b81b2651be9d0d91f19374db0b1c0d1b866c0db28cf49d20ecef1fc9a727cbf0a8f92d4096ff6b209f6305ea511caacc398abdcc21f50d94154d487569fe54b6ac2b4efdea39345";

    ft.upload(picUrl, url, win, fail, options); 
}
 function win(r) {
	 alert(r.response);
   //  $("#returnpic").attr("src","http://117.40.138.121:520/zms/files/"+ r.response);

     //$("#returninfo").html("上传成功\n：反馈的信息:r.responseCode:"+r.responseCode+"\nr.response:"+r.response+"\nr.bytesSent:"+r.bytesSent);
 }
 
/*  function uploadPicture(imageURL){
	 window.resolveLocalFileSystemURI(imageURL,function(imageFileEntry){
		 imageFileEntry.file(function(imageFile){
			 var options = new FileUploadOptions();
			 options.chunkedMode=false;
			 options.fileKey="file";
			 options.filename=imageFile.name;
			var url="http://192.168.1.127:908/mobilephone/upload.asp?userid=8b81b2651be9d0d91f19374db0b1c0d1b866c0db28cf49d20ecef1fc9a727cbf0a8f92d4096ff6b209f6305ea511caacc398abdcc21f50d94154d487569fe54b6ac2b4efdea39345";
			
			var fileTransfer=new FileTransfer();
			
			 fileTransfer.upload(imageFile.fullPath,url,uploadHandler,fileTransferErrorHandler,options,true);
			 
		 });

	 });
	 alert(111)
 } */
 
 function uploadImage(image) {alert(image)
	 var file=document.createElement("input");
         file.setAttribute("type","file");
         file.setAttribute("id","file");
         file.setAttribute("name","file");
         file.setAttribute("value",image);
	//var $file=$("<input>",{type:'file',val:image,id :"fileid"})
	alert(file.id);
         $.ajaxFileUpload({
             //type: "post",
             url:"http://192.168.1.127:908/mobilephone/upload.asp?userid=8b81b2651be9d0d91f19374db0b1c0d1b866c0db28cf49d20ecef1fc9a727cbf0a8f92d4096ff6b209f6305ea511caacc398abdcc21f50d94154d487569fe54b6ac2b4efdea39345",
             secureuri:false,  
             fileElementId:'file',                        //文件选择框的id属性  
             //contentType: "multipart/form-data",
             // cache: false,
             dataType : 'text',
             success: function(data) {
            	 alert(data)
             },
             error: function(XMLHttpRequest, textStatus, errorThrown) {
                 alert("上传失败，请检查网络后重试");
             }
         }); 
     }
 
 
 //所有获取图片失败都回调此函数
 function onLoadImageFail(message) {
     navigator.notification.alert("拍照失败，原因：" + message, null, "警告");
 }
 function loadImageLocal() {
     //获取本地图片并显示在屏幕
     navigator.camera.getPicture(onLoadImageLocalSuccess, onLoadImageFail, {
         destinationType: Camera.DestinationType.FILE_URI,
         sourceType: Camera.PictureSourceType.PHOTOLIBRARY
     });
 }
 function onLoadImageLocalSuccess(imageURI) {
	 return imageURI
    // $("#getImage").attr("src", imageURI);
    // $("#getImage").show();
 }
 function loadImageUpload() {
     navigator.camera.getPicture(onLoadImageUploadSuccess, onLoadImageFail, {
         destinationType: Camera.DestinationType.FILE_URI
     });
 }
 //图片拍照成功后回调此函数
 function onLoadImageUploadSuccess(imageURI) {
     //此处执行文件上传的操作，上传成功后执行下面代码
     var options = new FileUploadOptions(); //文件参数选项
     options.fileKey = "file";//向服务端传递的file参数的parameter name
     options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);//文件名
     options.mimeType = "image/jpeg";//文件格式，默认为image/jpeg
     var ft = new FileTransfer();//文件上传类
     ft.onprogress = function (progressEvt) {//显示上传进度条
         if (progressEvt.lengthComputable) {
             navigator.notification.progressValue(Math.round(( progressEvt.loaded / progressEvt.total ) * 100));
         }
     }
     var imgur="http://192.168.1.127:908/mobilephone/upload.asp?userid=8b81b2651be9d0d91f19374db0b1c0d1b866c0db28cf49d20ecef1fc9a727cbf0a8f92d4096ff6b209f6305ea511caacc398abdcc21f50d94154d487569fe54b6ac2b4efdea39345";
     navigator.notification.progressStart("提醒", "当前上传进度");url : ""
     ft.upload(imageURI, encodeURI(imgur), function () {
         navigator.notification.progressStop();//停止进度条
         alert(imageURI)
/*          $("#getImageUpload").attr("src", imageURI);
         $("#getImageUpload").show();  */
         navigator.notification.alert("文件上传成功！", null, "提醒");
     }, null, options);
 }

            
        </script>
        <title>富文本编辑器</title>
    </head>
    <body>

        <br style="clear:both"/>
        <textarea id="textarea"></textarea>
        <div id="editor">
            <span class="button" title="createlink" unselectable="on">选择</span>
            <span class="button" title="insertimage" unselectable="on">拍照</span>
        </div>
    </body>
</html>
